package View;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;
import java.io.IOException;


import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


import Model.IUpdatable;

import Presenter.SaveLoadPresenter;
/*
 * the view for the save screen
 */
public class SaveView extends JPanel implements IUpdatable{

	/**
	 * 
	 */
	private final SaveLoadPresenter presenter;
	
	/**
	 * 
	 */
	private final JButton saveButton;

	public SaveView(){
		
		saveButton = new JButton("Save Game");
		presenter = new SaveLoadPresenter();

		final JLabel whereLabel = new JLabel("Where to save?");
		final JButton save1 = new JButton("File 1");
		final JButton save2 = new JButton("File 2");
		final JButton save3 = new JButton("File 3");
		final GUI gui = GUI.getInstance();
		final JFrame frame = new JFrame();
		
		save1.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e){
				try {
                    presenter.saveGame(SaveLoadPresenter.FILE_NAMES[0]);
                    gui.setContentPane(new MainPageView(), 500, 430);
        			frame.add(new JLabel("you've saved"));
        			frame.setSize(300, 300);
        			frame.setVisible(true);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
			}
		});
		
		save2.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e){
				try {
                    presenter.saveGame(SaveLoadPresenter.FILE_NAMES[1]);
                    gui.setContentPane(new MainPageView(), 500, 430);
                    frame.add(new JLabel("you've saved"));
        			frame.setSize(300, 300);
        			frame.setVisible(true);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
				
			}
		});
		
		save3.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e){
				try {
                    presenter.saveGame(SaveLoadPresenter.FILE_NAMES[2]);
                    gui.setContentPane(new MainPageView(), 500, 430);
                    frame.add(new JLabel("you've saved"));
        			frame.setSize(300, 300);
        			frame.setVisible(true);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

			}
		});
		
		this.setLayout(new GridLayout(5, 2));
		this.add(whereLabel);
		this.add(new JLabel(""));
		this.add(new JLabel(""));
		this.add(new JLabel(""));
		this.add(save1);
		this.add(new JLabel(""));
		this.add(save2);
		this.add(new JLabel(""));
		this.add(save3);
		this.setVisible(true);
		
		
	}

	@Override 
	public void update(){
	    System.out.println("Blank");
	}

}
